package xiaodou.core.controls
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;
	
	import mx.controls.SWFLoader;
	import mx.core.FlexGlobals;
	import mx.managers.PopUpManager;
	
	public class Loading extends SWFLoader
	{
		private static var _instance:Loading;
		
		public static function get instance():Loading
		{
			if(_instance == null)
				_instance = new Loading();
			return _instance;
		}
		
		public function Loading()
		{
		}
		
		public function show():void
		{
			if(content == null)
			{
				addEventListener(Event.COMPLETE, completeHandler);
				load("../assets/loading.swf");
			}
			if(!parent)
			{
				PopUpManager.addPopUp(this, FlexGlobals.topLevelApplication as DisplayObject, true);
				PopUpManager.centerPopUp(this);
			}
			
		}
		
		protected function completeHandler(event:Event):void
		{
			PopUpManager.centerPopUp(this);
		}
		
		public function hide():void
		{
			PopUpManager.removePopUp(this);
		}
	}
}